class ReplicaSystemsController < ApplicationController
  include ApplicationHelper
  
  before_filter :login_required, :administration_required, :body_id
  
  def body_id
    @body_id = :configurations
  end
  
  def new
    @protocols = ReplicaSystem::PROTOCOLS
    @main_replica = ReplicaSystem.find_main_repository
  end
  
  def create
    @replica_system = ReplicaSystem.new(params[:replica_system])
	
  	if @replica_system.save
  	  flash[:notice] = 'Success on creating the new Storage System'
  	else
  	  flash[:error] = "Sorry, the Storage System can't be created. Try again"
  	end
  	
  	redirect_to :action => 'index'
  end
  
  def index
    @replication_systems = ReplicaSystem.find :all
  end
  
  def edit
    @protocols = ReplicaSystem::PROTOCOLS
    @replica_system = ReplicaSystem.find params[:id]
  end
  
  def show
    begin
      @replica_system = ReplicaSystem.find params[:id]
    rescue
      flash[:error] = "Sorry, the Storage System doesn't exist"
      redirect_to :action => 'index'
    end
  end
  
  def update
    @replica_system = ReplicaSystem.update_attributes(params[:replica_system])
    redirect_to :action => 'show', :id => @replica_system
  end
end
